package com.fresh.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * 返回数据
 * 
 * @author alex
 * @email gaonan.service@gmail.com
 * @date 2016年10月27日 下午9:59:27
 */
public class Response extends HashMap<String, Object> {

	private static final long serialVersionUID = 1L;

	public Response() {
		put("code", 0);
		put("success",false);
	}

	public static Response error() {
		return error(500, "未知异常，请联系管理员");
	}

	public static Response error(Object msg) {
		return error(500, msg);
	}
	
	public static Response error(int code, Object msg) {
		Response r = new Response();
		r.put("code", code);
		r.put("msg", msg);
		return r;
	}
	
	public static Response ok(Object data) {
		Response r = new Response();
		r.put("msg", "success");
		r.put("data",data);
		r.put("success",true);
		return r;
	}

	public static Response ok(Map<String, Object> map) {
		Response r = new Response();
		r.putAll(map);
		r.put("success",true);
		return r;
	}

	public static Response ok() {
		Response r = new Response();
		r.put("msg", "success");
		r.put("success",true);
		return  r;
	}

	public Response put(String key, Object value) {
		super.put(key, value);
		return this;
	}
}
